package cn.ywang.pattern.strategy;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 出行策略工厂
 *
 * @author BeatificWang
 * @date 2019/3/15 22:53
 */
public class TripStrategyFactory {

	private TripStrategyFactory() {
	}

	private static final Map<String, TripStrategy> STRATEGIES = new LinkedHashMap<>(2);

	static {
		STRATEGIES.put(TripStrategyKey.TAX, new TaxStrategy());
		STRATEGIES.put(TripStrategyKey.BUS, new BusStrategy());
		STRATEGIES.put(TripStrategyKey.METRO, new MetroStrategy());
		STRATEGIES.put(TripStrategyKey.WALK, new WalkStrategy());
	}

	public static TripStrategy getTripStrategy(String tripStrategyKey) {
		if (STRATEGIES.containsKey(tripStrategyKey)) {
			return STRATEGIES.get(tripStrategyKey);
		}
		else {
			return STRATEGIES.get(TripStrategyKey.WALK);
		}
	}

	private interface TripStrategyKey {
		String TAX = "tax";
		String BUS = "bus";
		String METRO = "metro";
		String WALK = "walk";
	}
}

